package com.xiaoshuidi.cloud.module.member.controller.admin.activities;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.excel.core.util.ExcelUtils;
import com.xiaoshuidi.cloud.module.member.controller.admin.activities.vo.ActivitiesStatisticsVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.activities.vo.EnrollItemVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.coupon.vo.CouponListExportVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.coupon.vo.CouponQueryForm;
import com.xiaoshuidi.cloud.module.member.controller.app.activities.vo.EnrollListVO;
import com.xiaoshuidi.cloud.module.member.controller.app.activities.vo.EnrollStatusPageVO;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.activities.MemberActivitiesEnrollService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import java.io.IOException;
import java.util.List;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 活动报名")
@RestController
@RequestMapping(ApiConstants.NAME+"/activity-enroll")
public class MemberActivityEnrollController {
    @Resource
    private MemberActivitiesEnrollService memberActivitiesEnrollService;

    @PostMapping("/get-page")
    @Operation(summary = "报名详情单个活动获取活动报名分页列表")
    public CommonResult<PageResult<EnrollListVO>> getPage(@RequestBody EnrollStatusPageVO page) {
        return success(memberActivitiesEnrollService.getPage(page));
    }
    @PostMapping("/export-enroll-list")
    @Operation(summary = "活动报名详情导出")
    public void exportEnrollList(@RequestBody EnrollStatusPageVO form, HttpServletResponse response) throws IOException {
        List<EnrollListVO> list = memberActivitiesEnrollService.exportEnrollList(form);
        ExcelUtils.write(response, "活动报名详情.xls", "活动报名详情", EnrollListVO.class, list);
    }


    @PostMapping("/write-off/{id}")
    @Operation(summary = "核销")
    public CommonResult<Boolean> writeOff(@PathVariable("id") Long id, @Valid @RequestBody EnrollItemVO enrollItemVO) {
        return success(memberActivitiesEnrollService.writeOff(id,enrollItemVO));
    }

    @PostMapping("/statistics/{activityId}")
    @Operation(summary = "单个活动统计信息")
    public CommonResult<List<ActivitiesStatisticsVO>> statistics(@PathVariable("activityId") Long activityId) {
        return success(memberActivitiesEnrollService.statistics(activityId));
    }


}
